package org.dromara.tearoom.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.tearoom.domain.bo.TerGroupBuyAppBo;
import org.dromara.tearoom.domain.enums.CouponPlateTypeEnum;
import org.dromara.tearoom.domain.vo.TerGroupBuyVo;
import org.dromara.tearoom.service.ICertificateCouponService;
import org.dromara.tearoom.service.IThirdGroupBuyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 团购核销实现类
 * @author CKJ
 * @description: TODO
 * @date 2025/5/8 16:56
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class CertificateCouponServiceImpl implements ICertificateCouponService {


    /**
     * 准备验劵
     *
     * @param bo
     * @return
     */
    @Override
    public List<TerGroupBuyVo> certificatePrepare(TerGroupBuyAppBo bo) {
        IThirdGroupBuyService groupBuyService;
        try {
            groupBuyService = SpringUtils.getBean(CouponPlateTypeEnum.fromType(bo.getPlateType()).name());
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("不支持当前平台!");
        }
        return groupBuyService.certificatePrepare(bo.getShortUrl(),bo.getCode(), bo.getPoiId());

    }

    /**
     * 核销验券
     *
     * @param bo
     */
    @Override
    public Boolean certificate(TerGroupBuyAppBo bo) {
        IThirdGroupBuyService groupBuyService;
        try {
            groupBuyService = SpringUtils.getBean(CouponPlateTypeEnum.fromType(bo.getPlateType()).name());
        }catch (Exception e){
            e.printStackTrace();
            throw new ServiceException("不支持当前平台!");
        }
        groupBuyService.certificate(bo.getEncryptedCode(), bo.getPoiId(),bo.getId());
        return true;
    }
}
